﻿using System;
using System.Collections;
using System.Web.UI.WebControls;
using Model;
using Service;
using Parameter=Model.Parameter;


public partial class EquipmentTypeDetail : System.Web.UI.Page
{
    readonly ReferenceDataService _ReferenceDataService = new ReferenceDataService();
    readonly StockService _StockService = new StockService();
    private DirectService _DirectService = new DirectService();
    private int equipmentTypeId = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        equipmentTypeId = GetEquipmentTypeId();
        IList list = new ArrayList();
        list = _ReferenceDataService.GetEquipmentTypeById(equipmentTypeId);
        txtHiddenTypeId.Text = equipmentTypeId.ToString();
        if(equipmentTypeId==0)
        {
            equipmentTypeId = Parameter.equipementTypeId;
            txtHiddenTypeId.Text = equipmentTypeId.ToString();
            list = _ReferenceDataService.GetEquipmentTypeById(equipmentTypeId);
        }

        if (list.Count != 0)
        {
            lblEquipmentTypeId.Text = equipmentTypeId.ToString();
            lblEquipmentType.Text = ((EquipmentType) (list[0])).EquipmentTypeLabel;
            lblSparepart.Text = ((EquipmentType) (list[0])).IsSparePart.ToString();
            lblBuiltIn.Text = ((EquipmentType) (list[0])).IsBuiltIn.ToString();
        }
        if(equipmentTypeId>0)
        {

            _DirectService.GetEquipmentTypeBySystem(equipmentTypeId.ToString());
 
        }
    }

    public int GetEquipmentTypeId()
    {
        return !String.IsNullOrEmpty(Request.QueryString["equipementTypeId"]) ? Int32.Parse(Request.QueryString["equipementTypeId"]) : 0;
    }
    protected void grdEquipment_PageIndexChanging(object sender, System.Web.UI.WebControls.GridViewPageEventArgs e)
    {

    }
    protected void grdEquipment_RowCancelingEdit(object sender, System.Web.UI.WebControls.GridViewCancelEditEventArgs e)
    {

    }
    protected void grdSystem_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
    {

        if (e.CommandName.Equals("Delete"))
        {
            int typeEquipmentId = Convert.ToInt32(grdSystem.DataKeys[Convert.ToInt32(e.CommandArgument)].Value);
            // _StockService.DeleteTypeEquipment(typeEquipmentId);
            _StockService.DeleteSystem(typeEquipmentId);
            Parameter.equipementTypeId = equipmentTypeId; 
            Response.Redirect("EquipmentTypeDetail.aspx");
        }
    }
    protected void grdSystem_RowDeleting(object sender, System.Web.UI.WebControls.GridViewDeleteEventArgs e)
    {

    }
    protected void grdSystem_RowEditing(object sender, System.Web.UI.WebControls.GridViewEditEventArgs e)
    {

    }
    protected void grdSystem_RowUpdated(object sender, System.Web.UI.WebControls.GridViewUpdatedEventArgs e)
    {

    }
    protected void grdSystem_RowUpdating(object sender, System.Web.UI.WebControls.GridViewUpdateEventArgs e)
    {

    }
    protected void grdEquipment_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void grdSystem_Sorted(object sender, EventArgs e)
    {

    }
    protected void grdEquipment_RowDataBound1(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //block to add message
            string stringComplete = "";
            if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
            {
                LinkButton deleteButton = (LinkButton)e.Row.Cells[1].Controls[0];
                deleteButton.Attributes.Add("onclick", "return confirm('" +Resources.Resource.ConfirmDeleteMessage +"');");
            }
        }
    }
}
